package com.example.module.custom.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.example.module.custom.R;
import com.example.module.custom.R2;
import com.example.module.custom.bean.MaterialsCodeBean;
import com.example.module.custom.bean.PlanBean;

import java.util.List;

import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @name BlockDemo
 * @class name：com.example.module.custom.adapter
 * @classdescribe
 * @anthor ljp
 * @time 2020/2/26 14:44
 */
public class ProduceCodeAdapter extends BaseAdapter<MaterialsCodeBean.DataListBean>{
    private String TAG = "ProduceCodeAdapter";
    /**
     * @param context activity_imessage
     * @param tlist   集合
     * @param mLayout 主布局
     */
    public ProduceCodeAdapter(Context context, List<MaterialsCodeBean.DataListBean> tlist, int mLayout) {
        super(context, tlist, mLayout);
    }

    @Override
    protected RecyclerView.ViewHolder getHeaderViewHolder(View view) {
        return new HeadViewHolder(view);
    }

    @Override
    protected RecyclerView.ViewHolder getItemViewHolder(View view) {
        return new ViewHolder(view);
    }

    @Override
    protected RecyclerView.ViewHolder getFooterViewHolder(View view) {
        return null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
        if(viewHolder instanceof HeadViewHolder){
            HeadViewHolder headViewHolder = (HeadViewHolder) viewHolder;
            headViewHolder.tvCode.setText("物料批次码");
            headViewHolder.tvCodeName.setText("物料名称");
            headViewHolder.tvNumber.setText("数量");
        }else  if(viewHolder instanceof ViewHolder){
            position = position -1;
            MaterialsCodeBean.DataListBean dataListBean = tlist.get(position);
            ((ViewHolder) viewHolder).tvCode.setText(dataListBean.getPartId());
            ((ViewHolder) viewHolder).tvCodeName.setText(dataListBean.getPartName());
            ((ViewHolder) viewHolder).tvNumber.setText(dataListBean.getNumber()+"");
        }

    }

    class ViewHolder extends BaseViewHolder{
        @BindView(R2.id.tv_code)
        TextView tvCode;
        @BindView(R2.id.tv_code_name)
        TextView tvCodeName;
        @BindView(R2.id.tv_number)
        TextView tvNumber;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
    class HeadViewHolder extends BaseViewHolder{
        @BindView(R2.id.tv_code)
        TextView tvCode;
        @BindView(R2.id.tv_code_name)
        TextView tvCodeName;
        @BindView(R2.id.tv_number)
        TextView tvNumber;
        public HeadViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
